<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算属性用法</title>
</head>
<body>
    <div id="app">
        总价: {{ prices }}
    </div>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script>
        let app = new Vue({
            el: '#app',
            data(){
                return{
                    package1: [
                        {
                            name: '林宝 1',
                            price: 8177,
                            count: 1
                        },
                        {
                            name: '小林子 3',
                            price: 3188,
                            count: 1
                        }
                    ],
                    package2:[
                        {
                            name: 'apple',
                            price: 3,
                            count: 8
                        },
                        {
                            name: 'banana',
                            price: 2,
                            count: 12
                        }
                    ]
                }
            },
            computed:{
                prices: function(){
                    let prices = 0;
                    for(let i = 0; i < this.package1.length; i++){
                        prices += this.package1[i].price * this.package1[i].count;
                    }
                    for(let i = 0; i < this.package2.length; i++){  
                        prices += this.package2[i].price * this.package2[i].count;
                    }
                    return prices;
                }
            },
            a(){
                return{
                    prices:32
                }
            }
        })
    </script>
</body>
</html>